<template>
  <a-modal destroyOnClose :title="$t('candidateApplication.normal_resume')" :visible="visible" :width="920" @cancel="cancelModal(false)" @ok="handleOk" class="ResumeEdit">
    <position-rec-desc :nodesc="true">
      <position-recReason :positionInfo="positionInfo.position" ref="reason" slot="content" :resumeData="resumeData" :enterpriseId="enterpriseId" :positionId="positionId" :recommendInfo="recommendInfo"/>
    </position-rec-desc>
  </a-modal>
</template>

<script>
import PositionRecDesc from '@/components/position/PositionRecDesc'
import PositionRecReason from '@/components/position/PositionRecReason'
import { updateRecommendInfo } from '@/api/resume'
export default {
  name: 'ResumeEdit',
  // props: ['visible', 'positionId', 'enterpriseId', 'recommendInfo', 'id', 'positionInfo', 'resumeData'],
  props: {
    visible: {
      type: Boolean,
      default: false,
      require: true
    },
    enterpriseId: { // 企业id
      type: String,
      required: true
    },
    positionId: { // 职位id
      type: String,
      required: true
    },
    id: { // 职位id
      type: String,
      required: true
    },
    recommendInfo: { // 推荐理由数据
      type: Object,
      required: false,
      default: function () {
        return {}
      }
    },
    positionInfo: { // 职位详细信息 用于回显模板数据
      type: Object,
      required: false,
      default: function () {
        return {}
      }
    },
    resumeData: { // 简历详细信息 用于回显模板数据
      type: Object,
      required: false,
      default: function () {
        return {}
      }
    }
  },
  components: { PositionRecReason, PositionRecDesc },
  data () {
    return {
    }
  },
  computed: {
  },
  methods: {
    async recReason (data) {
      this.loading = true
      let params = {
        id: this.id,
        ...data
      }
      let res = await updateRecommendInfo(params)
      if (res.code === 200) {
        this.$message.success(res.message)
        this.cancelModal(true)
      } else {
        this.$message.error(res.message)
      }
      this.loading = false
    },
    async handleOk () {
      let data = await this.$refs.reason.sendData()
      if (data) {
        this.recReason(data) // 上送数据
      } else {
        this.$message.error(`${this.$t('common.confirm_require')}！`)
      }
    },
    cancelModal (flag) {
      this.$emit('close', flag)
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '../../styles/var.styl'
</style>
<style lang="stylus">
.ResumeEdit
  :global(.ant-modal-content .ant-modal-body)
    padding 24px 0 0
</style>
